package backtrackAlgorithm;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

//电话号码的字母组合
public class LeetCode_17 {
    public List<String> letterCombinations(String digits) {
        ArrayList<String> list = new ArrayList<>();
        if (digits.length()==0){
            return list;
        }
        solution_1(digits,list,0,"");
        return list;
    }


    //暴力递归
    private void solution_1(String digits,List<String> list,int i,String currentValue) {
        //1. 最后一位
        if (i==digits.length()-1){
            List<Character> chars = getChar(Integer.parseInt(""+digits.charAt(i)));
            for (Character aChar : chars) {
                list.add(currentValue+aChar);
            }

            return;
        }
        //2. 其它情况
        List<Character> chars = getChar(Integer.parseInt(""+digits.charAt(i)));
        for (Character aChar : chars) {
            solution_1(digits,list,i+1,currentValue+aChar);
        }


    }

    //返回字符
    public List<Character> getChar(int i){
        ArrayList<Character> list = new ArrayList<>();
        if (i<=6){
            int start=(i-2)*3;
            list.add((char) ('a'+start));
            list.add((char) ('a'+start+1));
            list.add((char) ('a'+start+2));
        } else if (i==7) {
            list.add('p');
            list.add('q');
            list.add('r');
            list.add('s');
        } else if (i==8) {
            list.add('t');
            list.add('u');
            list.add('v');
        } else if (i==9) {
            list.add('w');
            list.add('x');
            list.add('y');
            list.add('z');
        }

        return list;
    }

}
